package FCRendering.sw;

import FCRendering.FCRConstants;
import FCRendering.FCRMaster;

@Deprecated
public class FCRSocketThread extends Thread{
	@Override
	public void run() {
		boolean a = true, b = true;
		while (a) {
			if (FCRMaster.fcv.isOpenConnect()) {
				if (FCRMaster.fcv.getInterfacenum() == 2) {
					a = creatseverFunction();
				}
				if (FCRMaster.fcv.getInterfacenum() == 3) {
					String str = FCRMaster.socket.connectServer(FCRMaster.playerbIp.getText(), Integer.valueOf(FCRMaster.playerbPort.getText()));
					FCRMaster.fcv.getMessage().add(str);
					if (str.indexOf(FCRConstants.SYSTEM + "服务器连接成功") > 0) {
						FCRMaster.fcv.setOpenConnect(false);
						FCRMaster.fcv.setConnect(true);
					} else {
						a = false;
						new FCRSendMessageThread().start();
						new FCRReceiveMessageThread(FCRSocketThread.this).start();
					}
				} 
			}
			try {
				Thread.sleep(50);
			} catch (Exception e) {
				// TODO: handle exception
			}
		}
	}
	/**
	 * 创建服务
	 * 
	 * @return
	 */
	public boolean creatseverFunction() {
//		String str = FCRMaster.socket.createServer();
//		FCRMaster.fcv.getMessage().add(str);
//		if (str.indexOf(FCRConstants.SYSTEM + "服务器创建成功") > -1) {
//			String st = FCRMaster.socket.waitClientConnect();
//			FCRMaster.fcv.getMessage().add(st);
//			if (st.indexOf(FCRConstants.SYSTEM + "客户端连接成功") > -1) {
//				new FCRSendMessageThread().start();
//				new FCRReceiveMessageThread(FCRSocketThread.this).start();
//				FCRMaster.fcv.setConnect(true);
//				FCRMaster.socket.sendMessge(FCRConstants.SYSTEM + "已选择的存档为 " + FCRMaster.saveList.getSaveNameOfNum(FCRMaster.fcv.getSaveMouseClick()));
//				return false;
//			} else FCRMaster.fcv.setOpenConnect(false);
//		} else
//			FCRMaster.fcv.setOpenConnect(false);
		return true;
	}// 创建服务方法结束
}
